package com.safewind.controller;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.safewind.model.AllValue;
import com.safewind.model.AllValueData;
import com.safewind.model.User;
import com.safewind.service.IAllValueService;
import com.safewind.service.IUserService;

@Controller
@RequestMapping("/allValue")
public class AllValueController {
	@Resource
	private IAllValueService allValueService;

	@Resource
	private IUserService userService;

	@RequestMapping("/getAll")
	@ResponseBody
	public Object getAll(HttpServletRequest request, HttpSession session) {
		Map<String, Object> map = new HashMap<String, Object>();
		List<AllValue> list = allValueService.getAll();
		List<AllValueData> rList = new ArrayList<AllValueData>();
		for (AllValue av : list) {
			User user = userService.getUserByMD5Id(av.getUserId());
			AllValueData avd = new AllValueData(av, user.getUserName());
			rList.add(avd);
		}
		map.put("list", rList);
		map.put("success", true);
		return map;
	}
}
